package com.agency8x.model;

import com.agency8x.model.base.BaseUserAgentModel;
import com.jfinal.plugin.activerecord.Page;

/**
 * Agency model.
 * 数据库字段名建议使用驼峰命名规则，便于与 java 代码保持一致，如字段名： userId
 */
@SuppressWarnings("serial")
public class UserAgentModel extends BaseUserAgentModel<UserAgentModel> {
	
	public static final UserAgentModel me = new UserAgentModel().dao();
	
	/**
	 * 所有 sql 与业务逻辑写在 Service 中，在此放在 Model 中仅为示例
	 */
	public Page<UserAgentModel> paginate(int pageNumber, int pageSize, String where) {
		String sql ="SELECT u.user_id, u.nickname,u.mobile,u.email,agt.top_agent_id, u.user_status, u.regist_time, agt.update_time ";
		String sqlFrom = "  FROM dbo.t_user_agent agt LEFT JOIN t_user u ON agt.user_id=u.user_id WHERE agt.top_agent_id > 0";
		return paginate(pageNumber, pageSize, sql,sqlFrom);
	}
	
	public UserAgentModel MiddlemanEdit(String user_id) {
		String sql ="SELECT u.user_id, u.nickname,u.mobile,u.email,agt.top_agent_id, u.user_status, u.regist_time, agt.update_time ";
		String sqlFrom = "  FROM dbo.t_user_agent agt LEFT JOIN t_user u ON agt.user_id=u.user_id WHERE agt.top_agent_id > 0  and u.user_id = ? ";
		return me.findFirst(sql+sqlFrom, user_id);
	}
}


